import { ObjCreate } from "../common/ObjCreate";
import { GImageBitmap } from "../../../../com/mui/controls/GImageBitmap";
import { Language } from "../../../../extend/language/Language";
import { GBox } from "../../../../com/mui/containers/GBox";
import { GBoxDirection } from "../../../../com/mui/containers/globalVariable/GBoxDirection";
import { WuXingImgFont } from "../player/wuxing/WuXingImgFont";
import { ImagesConst } from "../../resource/ImagesConst";
import { WXToolTipSprite } from "../player/wuxing/WXToolTipSprite";
import { WuXingPlayerInfo } from "../../model/wuxing/WuXingPlayerInfo";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { WuXingRule } from "../../rules/WuXingRule";
import { WuXingRefreshItem } from "./WuXingRefreshItem";
import { ObjectPool } from "../../../../com/gengine/utils/pools/ObjectPool";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
type int = number;
//class WuXingRefreshList
    
    export  class WuXingRefreshList /* flash.display.Sprite */
    {
        constructor(arg1: int, arg2: int, arg3: int, arg4: Boolean=true, arg5: int=20)
        {
            
            this._type = arg1;
            this._width = arg2;
            this._height = arg3;
            this._showBg = arg4;
            this._itemHeight = arg5;
            this.initUI();
            return;
        }

        protected initUI(): void
        {
            var loc1=null;
            if (this._showBg) 
            {
                this._bg = ObjCreate.createBg(0, 0, this.width, this.height, this);
            }
            var loc2=this._type;
            switch (loc2) 
            {
                case 0:
                {
                    this._attrBmp = new GImageBitmap("EquipRecast_current.png");
                    loc1 = Language.getString(26329);
                    break;
                }
                case 1:
                {
                    this._attrBmp = new GImageBitmap("EquipRecast_new.png");
                    loc1 = Language.getString(26330);
                    break;
                }
            }
            this._attrBmp.x = -5;
            this._attrBmp.y = -5;
            if (!this._showBg) 
            {
            };
            this._attrTxt = ObjCreate.createTextField(loc1, 50, 10, 60, 20, this);
            this._attrTxt.textColor = 16760577;
            this._attrTxt.mouseEnabled = false;
            this._gbox = new GBox();
            this._gbox.direction = GBoxDirection.VERTICAL;
            this._gbox.x = 10;
            this._gbox.y = 33;
            addChild(this._gbox);
            this._fontImg = new WuXingImgFont(ImagesConst.Fire, 145, false, Language.getStringByParam(26410, 0));
            this._fontImg.mouseChildren = false;
            this._fontImg.mouseEnabled = false;
            this._fontImg.x = 5;
            this._fontImg.y = this.height - 24;
            addChild(this._fontImg);
            this._tipsBg = new WXToolTipSprite(this.width, this.height);
            this._tipsBg.x = 0;
            this._tipsBg.y = 0;
            addChild(this._tipsBg);
            return;
        }

        public updateData(arg1: WuXingPlayerInfo, arg2: int=0): void
        {
            this._info = arg1;
            this.clearAttrList();
            if (this._type != 0) 
            {
                this._index = arg2;
                if (arg1.vitalsAddition < arg1.getNewVitalsAddition(arg2)) 
                {
                    this._fontImg.updateCompare(1);
                }
                this.refreshList(arg1.getNewAttrList(arg2), arg1.getNewVitalsAddition(arg2), this._showBg);
            }
            else 
            {
                this.refreshList(arg1.attrList, arg1.vitalsAddition);
                this._tipsBg.toolTipData = HTMLUtil.addColor(Language.getStringByParam(26360, this._info.getMainAttrHtmlName(), this._info.getMainAttrHtmlName(), WuXingRule.getRelationName(this._info.mainAttribute, WuXingRule.Relation_AddFrom, true), WuXingRule.getRelationName(this._info.mainAttribute, WuXingRule.Relation_DelFrom, true)), "#ffffff");
            }
            return;
        }

        public updateLockMainAttr(): void
        {
            var loc1=0;
            var loc3=null;
            var loc2=this._gbox.numChildren;
            while (loc1 < loc2) 
            {
                loc3 = this._gbox.getChildAt(loc1) as WuXingRefreshItem;
                loc3.updateLockMainAttr();
                ++loc1;
            }
            return;
        }

        /* internal  */refreshList(arg1: Array<any>, arg2: number, arg3: Boolean=false): void
        {
            var loc1=0;
            var loc2=0;
            var loc3=null;
            var loc4=null;
            if (arg1) 
            {
                if (arg1.length > 0) 
                {
                    loc2 = arg1.length;
                    while (loc1 < loc2) 
                    {
                        loc3 = arg1[loc1];
                        (loc4 = ObjectPool.getObject(WuXingRefreshItem)).height = this._itemHeight;
                        loc4.updateData(loc3, arg3 && this._showBg);
                        this._gbox.addChild(loc4);
                        ++loc1;
                    }
                    this._gbox.invalidate();
                    this._fontImg.updateTxt(Language.getStringByParam(26410, arg2 + "%"));
                }
            }
            return;
        }

        public invalidate(): void
        {
            this._gbox.drawNow();
            return;
        }

        public clearAttrList(): void
        {
            var loc1=null;
            this._tipsBg.toolTipData = null;
            while (this._gbox.numChildren > 0) 
            {
                loc1 = this._gbox.removeChildAt(0) as WuXingRefreshItem;
                loc1.dispose();
                ObjectPool.disposeObject(loc1, WuXingRefreshItem);
            }
            this._fontImg.updateTxt(Language.getStringByParam(26410, "0%"));
            this._fontImg.dispose();
            return;
        }

        public dispose(): void
        {
            return;
        }

        public get index(): int
        {
            return this._index;
        }

        public /* override */ get height(): number
        {
            return this._height;
        }

        public /* override */ get width(): number
        {
            return this._width;
        }

        /* internal */ /* var */_type: int;

        /* internal */ /* var */_showBg: Boolean;

        /* internal */ /* var */_itemHeight: int;

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_attrBmp: GImageBitmap;

        /* internal */ /* var */_attrTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_gbox: GBox;

        /* internal */ /* var */_fontImg: WuXingImgFont;

        /* internal */ /* var */_width: int;

        /* internal */ /* var */_height: int;

        public /* var */_info: WuXingPlayerInfo;

        /* internal */ /* var */_tipsBg: WXToolTipSprite;

        /* internal */ /* var */_nullImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_index: int;
    }
